//
//  PlaySound.m
//  NhomMinhThuy
//
//  Created by HOCVIEN on 5/9/15.
//  Copyright (c) 2015 Module4. All rights reserved.
//

#import "PlaySound.h"

@interface PlaySound ()
@property (strong, nonatomic) NSURL *musicURL;
@property (nonatomic) AVAudioPlayer *musicBackground;
@end

@implementation PlaySound

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.musicURL = [[NSBundle mainBundle]URLForResource:@"La Toi" withExtension:@"mp3"];
    
    self.musicBackground = [[AVAudioPlayer alloc]initWithContentsOfURL:self.musicURL error:nil];
    self.musicBackground.numberOfLoops = -1;
    self.music1.backgroundColor = [UIColor orangeColor];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (IBAction)playButClick:(UIButton *)sender {
    if ([self.musicBackground play]) {
        [self.musicBackground stop];
        //UIImageView *imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Pause.png"]];
        [self.playButt setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
    }
    else {
        [self.musicBackground play];
        [self.playButt setImage:[UIImage imageNamed:@"Pause.png"] forState:UIControlStateNormal];
    }
    
}

- (IBAction)music1:(UIButton *)sender {
    self.musicURL = [[NSBundle mainBundle]URLForResource:@"La Toi" withExtension:@"mp3"];
    self.music1.backgroundColor = [UIColor orangeColor];
    self.music2.backgroundColor = [UIColor blueColor];
}

- (IBAction)music2:(UIButton *)sender {
    self.musicURL = [[NSBundle mainBundle]URLForResource:@"MotNha" withExtension:@"mp3"];
    self.music2.backgroundColor = [UIColor orangeColor];
    self.music1.backgroundColor = [UIColor blueColor];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
